<?php
	include "../../public/commom/config.php";
	include "../lock2.php";
	
	if($_GET) {
		$id = $_GET["id"];
		
		$sql = "SELECT * FROM news where id = $id";
		
		$result = mysqli_query($conn, $sql);
		
		while($row = mysqli_fetch_array($result)) {
			$title = $row["title"];
			$content = $row["content"];
			$class_id = $row["class_id"];
		}
	}
?>

<!DOCTYPE html>
<html>
	
	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="../public/css/index.css"/>
	</head>
	
	<body>
			<h1>修改新闻</h1>
			<form action="modify1.php" method="post">
				<label>
					分类
					<select name="class_id">
						<?php 
							$sql = "SELECT * FROM class";
							
							$result = mysqli_query($conn, $sql);
							
							while($row = mysqli_fetch_array($result)) {
								if($row["id"] == $class_id) {
									echo "<option value=" . $row["id"] . " selected>" . $row["name"] . "</option>";
								}else {
									echo "<option value=" . $row["id"] . ">" . $row["name"] . "</option>";
								}
								
							}
							
							mysqli_close($conn);
						?>
					</select>
				</label>
				<label>
					标题
					<input type="text" name="title" value="<?php echo $title?>" placeholder="请输入标题..." autocomplete="off" />
				</label>
				<label>
					内容
					<input type="text" name="content" value="<?php echo $content?>" placeholder="请输入内容..." autocomplete="off" />
				</label>
				<input type="hidden" name="id" value="<?php echo $id?>" />
				<input type="submit" value="修改"/>
			</form>
	</body>
	
</html>